import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';

import 'edit_nickname_logic.dart';

class EditNicknamePage extends StatelessWidget {
  const EditNicknamePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<EditNicknameLogic>(
      init: EditNicknameLogic(),
      builder: (controller) {
        return Scaffold(
          appBar: AppBar(
            title: Text(controller.type == 0 ? '修改昵称' : "性别"),
            actions: [
              InkWell(
                  onTap: () {
                    controller.onSubmit();
                  },
                  child: Padding(
                    padding: EdgeInsets.only(right: 12),
                    child: Text(
                      '保存',
                      style: TextStyle(
                        color: Color(0xff666666),
                        fontSize: 14,
                        fontWeight: FontWeight.w400,
                      ),
                    ),
                  )),
              18.w.sizeBoxW,
            ],
          ),
          body: Padding(
            padding: EdgeInsets.symmetric(horizontal: 18.w),
            child: controller.type == 0 ? _buildEditName(controller) : _buildGender(controller),
          ),
        );
      },
    );
  }

  Widget _buildGender(EditNicknameLogic controller) {
    return SizedBox(
      height: 180,
      child: ListView(
          padding: EdgeInsets.only(top: 50),
          children: List.generate(
            controller.textList.length,
            (index) => InkWell(
                child: Column(
                  children: [
                    Row(
                      children: [
                        Container(
                            alignment: Alignment.center,
                            height: 48.0,
                            margin: EdgeInsets.symmetric(horizontal: 16),
                            child: Text(
                              controller.textList[index],
                              style: TextStyle(color: Colors.white, fontSize: 18),
                            )),
                        Spacer(),
                        Visibility(
                            visible: controller.selectIndex == index,
                            child: Image.asset(
                              "mine_check_icon.png".mineImgPath,
                              width: 24,
                            ))
                      ],
                    ),
                    Container(
                      color: Colors.white10,
                      height: 0.5,
                    )
                  ],
                ),
                onTap: () {
                  controller.generateGender(index);
                  // Navigator.pop(context);
                }),
          )),
    );
  }

  Widget _buildEditName(EditNicknameLogic controller) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        57.h.sizeBoxH,
        Container(
          child: Text(
            '你的昵称',
            style: TextStyle(color: Colors.white, fontSize: 27.sp, fontWeight: FontWeight.w600),
          ),
        ),
        8.sizeBoxH,
        Container(
          decoration: const BoxDecoration(
            border: Border(
              bottom: BorderSide(color: Color(0xff212121), width: 1),
            ),
          ),
          child: Row(
            children: [
              Expanded(
                child: TextField(
                  controller: controller.editingController,
                  maxLines: 1,
                  maxLength: 10,
                  style: TextStyle(
                    color: const Color(0xffffffff),
                    fontSize: 18.sp,
                  ),
                  decoration: InputDecoration(
                    hintText: "输入新的昵称",
                    hintMaxLines: 1,
                    border: InputBorder.none,
                    hintStyle: TextStyle(
                      color: const Color(0xff999999),
                      fontSize: 18.sp,
                    ),
                    counterText: '',
                  ),
                  textInputAction: TextInputAction.done,
                  onSubmitted: (text) {
                    controller.onSubmit();
                  },
                ),
              ),
              GestureDetector(
                onTap: () {
                  controller.editingController.text = '';
                  controller.update();
                },
                child: Container(
                  padding: EdgeInsets.all(2),
                  decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(50)),
                  child: Icon(
                    Icons.close,
                    size: 13,
                  ),
                ),
              )
            ],
          ),
        ),
        SizedBox(height: 12),
        Text(
          "昵称30天内可修改4次",
          style: TextStyle(
            fontSize: 12.sp,
            color: const Color(0x4dffffff),
          ),
        ),
      ],
    );
  }
}
